<?php

/**
 * 解压zip文件
 */
function unzip() {
    $zip = new ZipArchive;
    $res = $zip->open('test.zip');
    if ($res === TRUE) {
        echo 'ok';
        $zip->extractTo('test'); //指定解压目录
        $zip->close();
    } else {
        echo 'failed, code:' . $res;
    }
}


function  createZip() {
    $zip = new ZipArchive;
    $res = $zip->open('test.zip', ZipArchive::CREATE);
    if ($res === TRUE) {
        $zip->addFromString('test.txt', 'file content goes here');
//        $zip->addFromString('test2.txt', 'file2 content goes here');
   //     $zip->addFile('data.txt', 'entryname.txt');
        $zip->close();
        echo 'ok';
    } else {
        echo 'failed';
    }
}

createZip();
